﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.IO;

namespace ECSE6770
{
    public static class VideoManager
    {
        public static string VideoFolder
        {
            get { return ConfigurationManager.AppSettings["VideoStorageLoc"]; }
        }

        public static int ContainerMaxWidth
        {
            get { return Int32.Parse(ConfigurationManager.AppSettings["VideoMaxWidth"]); }
        }

        /// <summary>
        /// Stores a file in the VideoFolder, and renames it to GUID.extension, and returns the new file name.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static string StoreVideo(HttpPostedFileBase file)
        {
            string fileName = String.Concat(Guid.NewGuid().ToString(), new FileInfo(file.FileName).Extension.ToLower());
            file.SaveAs(FullyQualifyFile(fileName));
            return fileName;
        }

        public static void UpdateVideoFile(Video v, HttpPostedFileBase file)
        {
            file.SaveAs(FullyQualifyFile(v.FileName));
        }

        public static void DeleteVideoFile(Video v)
        {
            File.Delete(FullyQualifyFile(v.FileName));
        }

        public static string FullyQualifyFile(string fileName)
        {
            return Path.Combine(VideoFolder, fileName);
        }
    }
}